﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartConference.Api.Applocations.IServices;
using SmartConference.Api.DTO;
using SmartConference.Domain;
using SmartConference.ErrorCode;
using SmartConference.Infrastructure.Implements;
using SmartConference.Infrastructure.Interfaces;

namespace SmartConference.Api.Controllers
{
    /// <summary>
    /// 角色管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        private readonly IRoleServices roleServices;

        public RoleController(IRoleServices roleServices)
        {
            this.roleServices = roleServices;
        }


        /// <summary>
        /// 新增职务
        /// </summary>
        /// <param name="addRoleDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddRole(AddRoleDTO addRoleDTO)
        {
            try
            {
                return await roleServices.AddRole(addRoleDTO);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="RoleId">角色Id</param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DeleteRole(int RoleId)
        {
            try
            {
                return await roleServices.DeleteRole(RoleId);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <param name="RoleName">职务名称</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<RoleInfo>>> GetRole(string? RoleName)
        {
            return await roleServices.GetRole(RoleName);
        }

        /// <summary>
        /// 设置角色状态
        /// </summary>
        /// <param name="RoleId">角色Id</param>
        /// <param name="RoleStatus">角色状态</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdateRoleState(int RoleId, int RoleStatus, string ContentDesc)
        {
            return await roleServices.UpdateRoleState(RoleId, RoleStatus,ContentDesc);
        }

        /// <summary>
        /// 编辑职务
        /// </summary>
        /// <param name="Roleid">角色Id</param>
        /// <param name="RoleName">职务名称</param>
        /// <param name="DepartmentDescription">职务描述</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdateRole(int Roleid, string RoleName, string DepartmentDescription)
        {
            try
            {
                return await roleServices.UpdateRole(Roleid, RoleName, DepartmentDescription);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
